package com.lechicanh.cgrid.ke.handler.launcher;

import java.rmi.RemoteException;
import java.util.logging.Logger;

import com.lechicanh.cgrid.ke.api.util.Util;
import com.lechicanh.cgrid.ke.handler.service.HandlerServiceDeployment;

public class Launcher {
	private static final Logger m_logger = Logger.getLogger("Hanlder");
	public static void main(String[] args) {
		String fromPage = Util.getParameter(args, "from");
		String toPage = Util.getParameter(args, "to");
		if(fromPage == null){
			System.out.println("Error!: need to input -from parameter");
			usage();
			return;
		}
		if(toPage == null){
			System.out.println("Error!: need to input -to parameter");
			usage();
			return;
		}
		Long lFromPage = Long.valueOf(fromPage);
		Long lToPage = Long.valueOf(toPage);
		System.out.println("Start handler");
		try {
			HandlerServiceDeployment.deploy(lFromPage, lToPage);
		} catch (RemoteException e) {
			System.out.println("Error!:" + e.getMessage() + ", closing hannlder");
		}
	}
	
	private static final void usage(){
		System.out.println("Usage: java -jar handler.jar -from [number] -to [number]"); 
	}
}

